<template>
  <div style="width: 100%;" class="f-column-Wcenter">
    <div class="header" style="width: 98%;">
      <div style="width: 100%;margin: 20px 0;" class="f-row-Hcenter">
        <el-input style="width: 200px;" v-model="query1.realName" placeholder="姓名"></el-input>
        <el-input style="width: 200px;margin-left: 30px;" v-model="query1.account" placeholder="手机号或者邮箱"></el-input>
        <el-date-picker style="margin-left: 30px;width: 300px;" v-model="query1.startTime" type="datetime"
         value-format="yyyy-MM-dd HH:mm:ss" placeholder="开始时间" align="right" :picker-options="pickerOptions">
        </el-date-picker>
        <el-date-picker style="margin-left: 30px;width: 300px;" v-model="query1.endTime" type="datetime"
         value-format="yyyy-MM-dd HH:mm:ss" placeholder="结束时间" align="right" :picker-options="pickerOptions">
        </el-date-picker>
        <el-dropdown style="margin-left: 30px;" @command="handleCommand1">
          <el-button type="primary">
            {{query1.command}}<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="">全部</el-dropdown-item>
            <el-dropdown-item command="0">未认证</el-dropdown-item>
            <el-dropdown-item command="1">初级认证通过</el-dropdown-item>
            <el-dropdown-item command="2">高级认证中</el-dropdown-item>
            <el-dropdown-item command="3">高级认证通过</el-dropdown-item>
            <el-dropdown-item command="4">高级认证不通过</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-button style="margin-left: 30px;" type="primary" icon="el-icon-search" @click="getTable(1)">搜索</el-button>
      </div>
    </div>
    <div class="table-box">
      <el-table ref="multipleTable" :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">>

        <el-table-column prop="realName" label="姓名">
        </el-table-column>
        <el-table-column prop="phone" label="手机">
        </el-table-column>
        <el-table-column prop="email" label="邮箱">
        </el-table-column>
        <el-table-column prop="createTime" label="加入时间">
        </el-table-column>
        <el-table-column prop="status" label="KYC认证状态">
          <template slot-scope="scope">
            <div class="f-row-Wcenter" style="color:#ff8f0f;">
              {{scope.row.status == 0 ?'未认证':''}}
              {{scope.row.status == 1 ?'初级认证通过':''}}
              {{scope.row.status == 2 ?'高级认证中':''}}
              {{scope.row.status == 3 ?'高级认证通过':''}}
              {{scope.row.status == 4 ?'高级认证不通过':''}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" class="f-row-Hcenter">
          <template slot-scope="scope">
            <div class="f-row-Hcenter">
              <el-button @click="toDetails(scope.row)" type="text" size="small">详情</el-button>
            </div>
          </template>

        </el-table-column>
      </el-table>
      <div style="width: 100%;margin-top: 20px;" class="f-row-Hcenter">
        <div>
          <span>【功能待补充】</span>
          <el-button @click="toggleSelection([...tableData])">全选</el-button>
          <el-button @click="toggleSelection()">取消选择</el-button>
          <el-button @click="topage('发送短信')">发送短信</el-button>
          <el-button @click="topage('发送邮件')">发送邮件</el-button>
          <el-button @click="topage('导出')">导出</el-button>
        </div>
        <el-pagination style="margin-left: 100px;" background layout="prev, pager, next" :page-size="query1.pageSize"
          :total="query1.total" @prev-click="onprevclick" @next-click="onnextclick" @current-change="onCurrentChange">
        </el-pagination>

      </div>
    </div>
  </div>
</template>

<script>
  import serveApi from "@/api/serveApi"
  export default {
    data() {
      return {
        pickerOptions: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        userId: '',
        query1: {
          account: '', //string(query) Z账号，输入手机号或者邮箱
          createTime: '', //string($date-time)加入时间
          email: '', // string邮箱
          phone: '', // string手机
          realName: '', //string真实名称
          status: '', //string0-未认证，1-初级认证通过，2-高级认证中，3-高级认证通过，4高级认证不通过

          command: '全部',
          pageNum: 1, //integer($int32)页码
          pageSize: 6, //integer($int32)每页大小
          currentPage: 0, //当前页数
          totalPage: 1, //总页数
          total: 0, //总条数条数
          toastTitle: false, //显示加载
        },
        tableData: [{
          createTime: '', //string($date-time)加入时间
          email: '', // string邮箱
          phone: '', // string手机
          realName: '', //string真实名称
          status: '', //string0-未认证，1-初级认证通过，2-高级认证中，3-高级认证通过，4高级认证不通过
        }],
        multipleSelection: []
      }
    },
    mounted() {
      this.getTable(1);
    },
    methods: {
      toDetails(row) {
        this.$router.push({
          name: "userOrdinaryDetails",
          query: row
        })
      },
      getTable(pageNum) {
        let that = this;
        if (pageNum > 0) {
          that.query1.pageNum = pageNum;
        }
        if (that.userId) {
          that.$message.error('userId为空')
          return;
        }

        serveApi.user_pageUser(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              //分页请求
              that.tableData = res.data;
              that.query1.totalPage = res.pages;
              that.query1.total = res.total;
              if (that.query1.currentPage >= that.query1.totalPage) {
                that.query1.toastTitle = true;
              } else {
                that.query1.toastTitle = false;
                that.query1.currentPage = that.query1.pageNum;
                that.query1.pageNum = that.query1.pageNum + 1;
              }
            }
          } else {
            that.$message.error(res.message);
          }
        });

      },
      onprevclick() {
        this.query1.currentPage = this.query1.currentPage - 1;
        this.query1.pageNum = this.query1.currentPage;
        this.getTable();
      },
      onnextclick() {
        this.getTable();
      },
      onCurrentChange(e) {
        this.getTable(e);
      },
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      topage(e) {
        console.log(e)
      },
      handleCommand1(command) {
        this.query1.status = command;
        if (this.query1.status == "") {
          this.query1.command = '全部';
          delete this.query1.status;
        }
        if (this.query1.status == 0) {
          this.query1.command = '未认证';
        }
        if (this.query1.status == 1) {
          this.query1.command = '初级认证通过';
        }
        if (this.query1.status == 2) {
          this.query1.command = '高级认证中';
        }
        if (this.query1.status == 3) {
          this.query1.command = '高级认证通过';
        }
        if (this.query1.status == 4) {
          this.query1.command = '高级认证不通过';
        }

      },

    }
  }
</script>

<style scoped lang="scss">
  .header {
    margin-top: 30px;
  }

  .table-box {
    width: 98%;
  }
</style>
